package cn.jdy.common.bo;

//import com.fasterxml.jackson.annotation.JsonIdentityInfo;
//import com.fasterxml.jackson.annotation.ObjectIdGenerators;

/**
 * 统一的 HTTP 响应格式。<br/>
 * code 为 "ok" 表示业务调用成功，否则是失败的错误码，如果有多个则以逗号分隔。<br/>
 * data 是业务数据，如果失败了则是 null。
 *
 * Created by Tianyi on 2014/7/23.
 */
//@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@statusCode")
public class RespBody {
	public static final int OK_CODE = 200;
	public static final int ERROR_CODE = 500;
	private final int statusCode;
	private final Object data;

	private static final RespBody OK = new RespBody(OK_CODE, null);
	private static final RespBody ERROR = new RespBody(ERROR_CODE, null);

	private RespBody(int statusCode, Object data) {
		this.statusCode = statusCode;
		this.data = data;
	}

	public static RespBody ok() {
		return OK;
	}

	public static RespBody ok(Object data) {
		return new RespBody(OK_CODE, data);
	}

	public static RespBody error() {
		return ERROR;
	}

	public static RespBody error(int statusCode) {
		return new RespBody(statusCode, null);
	}

	public static RespBody error(int statusCode, Object msg) {
		return new RespBody(statusCode, msg);
	}
}
